import {ROLE} from '@/services/api'
import {request, METHOD} from '@/utils/request'

/**
 *
 * @param pageQuery
 * @returns Promise<AxiosResponse>
 */
export async function page(pageQuery) {
    return request(ROLE.ROLE_PAGE, METHOD.POST, {
        ...pageQuery
    })
}

/**
 *
 * @returns  Promise<AxiosResponse>
 */
export async function list() {
    return request(ROLE.ROLE_LIST, METHOD.POST, {})
}

/**
 *
 * @param id
 * @returns Promise<AxiosResponse>
 */
export async function del(id) {
    return request(ROLE.ROLE_DELETE + `/${id}`, METHOD.POST, {})
}

/**
 *
 * @param formation
 * @returns Promise<AxiosResponse>
 */
export async function save(formation) {
    return request(ROLE.ROLE_ADD_OR_UPDATE, METHOD.POST, {
        ...formation,
    })
}


/**
 *
 * @param roleId  角色id
 * @param menuIds 菜单ids
 * @returns Promise<AxiosResponse>
 */
export async function authorized(roleId, menuIds) {
    return request(ROLE.ROLE_AUTHORIZED + `/${roleId}`, METHOD.POST, [...menuIds])
}

/**
 *
 * @param roleId  角色id
 * @returns Promise<AxiosResponse>
 */
export async function auths(roleId) {
    return request(ROLE.ROLE_AUTHS + `/${roleId}`, METHOD.GET, {})
}

export const columns = [
    {
        title: '角色名称',
        dataIndex: 'name',
        align: 'center',
    },
    {
        title: '角色编码',
        dataIndex: 'code',
        align: 'center',
    },
    {
        title: '更新时间',
        dataIndex: 'updateTime',
        align: 'center',
    },
    {
        title: '备注',
        dataIndex: 'remark',
        align: 'center',
    },
    {
        title: '操作',
        align: 'center',
        scopedSlots: {customRender: 'action'}
    }
]
